import time
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from selenium.webdriver.common.alert import Alert

chrome_options=Options( )
chrome_options.binary_location = r"D:\work\soft\Chrome\Application\chrome.exe"
d = webdriver.Chrome(options=chrome_options)
d.get('file:///D:/OneDrive/%E6%A1%8C%E9%9D%A2/alert.html')
d.maximize_window()

dj=d.find_element_by_id('1').click()
time.sleep(1)

#出现弹窗
# #切换作用域到弹窗，并获取弹窗对象
# #需通过该弹窗对象进行操作
# #确定 取消 输入框
alert:Alert = d.switch_to.alert
alert.send_keys("1")
alert.accept()
time.sleep(1)

qr=d.find_element_by_id('2')
qr.click()
alert.accept()
time.sleep(1)

qx=d.find_element_by_xpath("//div/input[3]")
qx.click()
alert.dismiss()
time.sleep(1)

